unit F_PrintDialog;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, Mask, JvExMask, JvSpin, JvDBSpinEdit,
  JvExStdCtrls, JvEdit, JvValidateEdit, DBCtrls, DB, ZAbstractRODataset,
  ZAbstractDataset, ZAbstractTable, ZDataset;

type
  TFPrintDialog = class(TForm)
    Panel1: TPanel;
    B_Aceptar: TButton;
    B_Cancelar: TButton;
    GB_Imprimir: TGroupBox;
    GB_Intervalo: TGroupBox;
    GB_Copias: TGroupBox;
    ComboBox1: TComboBox;
    Label1: TLabel;
    Label2: TLabel;
    Edit_Inicial: TJvValidateEdit;
    Edit_Final: TJvValidateEdit;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    CB_Orientacion: TComboBox;
    JvSE_Copias: TJvSpinEdit;
    B_Propiedades: TButton;
    Label6: TLabel;
    T_PaperSize: TZTable;
    DS_PaperSize: TDataSource;
    DB_PaperSize: TDBLookupComboBox;
    procedure FormCreate(Sender: TObject);
    procedure B_PropiedadesClick(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    constructor Create(Ini_Page, Fin_Page, Copies, Orientacion, PaperSize, PageCount:integer);
  end;


implementation

uses WinSpool, Printers, DM_Persistencia;

{$R *.dfm}

procedure TFPrintDialog.FormCreate(Sender: TObject);
begin
  ComboBox1.Items.Assign(Printer.Printers);
  ComboBox1.ItemIndex:= Printer.PrinterIndex;
  T_PaperSize.Active:= True;
  DB_PaperSize.KeyValue:= 5;
end;

constructor TFPrintDialog.Create(Ini_Page, Fin_Page, Copies, Orientacion, PaperSize, PageCount:integer);
begin
  inherited Create(nil);

  Edit_Inicial.MaxValue:= PageCount;
  Edit_Final.MaxValue:= PageCount;
  Edit_Final.Value:= PageCount;
  JvSE_Copias.Value:= Copies;
  CB_Orientacion.ItemIndex:= Orientacion;
  DB_PaperSize.KeyValue:= PaperSize;
end;


procedure TFPrintDialog.B_PropiedadesClick(Sender: TObject);
const
  {
   The TPrinterDefaults structure specifies the default data type,
   environment, initialization data, and access rights for a printer.
  }
  Defaults: TPrinterDefaults = (pDatatype: nil;
    pDevMode: nil;
    DesiredAccess: STANDARD_RIGHTS_REQUIRED or PRINTER_ACCESS_USE);
var
  hPrinter: THandle;
  Device: array[0..255] of char;
  Driver: array[0..255] of char;
  Port: array[0..255] of char;
  hDeviceMode: THandle;
  RetVal: Boolean;
begin
  Printer.PrinterIndex := Combobox1.ItemIndex;
  { Retrieve information about the specified printer }
  Printer.GetPrinter(Device,
    Driver,
    Port,
    hDeviceMode);
  { Retrieve a handle identifying the specified printer or print }
  if not OpenPrinter(@Device, hPrinter, @Defaults) then
    RaiseLastWin32Error;
  try
    { Display a printer-properties property sheet for the specified printer }
    PrinterProperties(Handle, hPrinter);
  finally
    { Close the specified printer object }
    ClosePrinter(hPrinter);
  end;
end;

procedure TFPrintDialog.Button1Click(Sender: TObject);
var
  MyPrinter, MyDriver, MyPort: array[0..100] of Char;
  PrinterHandle, DevMode: THandle;
begin
  Printer.GetPrinter(MyPrinter, MyDriver, MyPort, DevMode);
  OpenPrinter(MyPrinter, PrinterHandle, nil);
  PrinterProperties(Self.Handle, PrinterHandle);
end;


end.
